<template>
	<Modal :value="show" title="导入客观题结果" :width="50" @on-cancel="closeModal" footer-hide> 
		<template v-if="successData.length > 0">
			<h4>导入成功题目：</h4>
			<Table :data="successData" :columns="columns" border>
			
			</Table>
		</template>
		<template v-if="failData.length > 0">
			<h4>导入失败题目：</h4>
			<Table :data="failData" :columns="columns" border>
			
			</Table>
		</template>
	</Modal>
</template>
<script>
import { escape2Html } from '@/libs/utils'

export default {
	name:'ImportObjectiveFailModal',
	props:{
		'data':{
			type:Object,
			default:function(){
				return {}
			}
		},
		'show':{
			type:Boolean,
			default:false
		}
	},
	computed:{
		successData(){
			return this.data.successData || []
		},
		failData(){
			return this.data.failData || []
		},
	},
	data(){
		return {
			columns:[
				{
					title:'题目名称',
					key:'data',
					render:(h,params) => {
						return h('span',this.escape2Html(params.row.data))
					}
				},
				{
					title:'结果',
					key:'message',
					render:(h,params) => {
						return h('span',this.escape2Html(params.row.message))
					}
				}
			]
		}
	},
	mounted(){
		
	},
	methods:{
		escape2Html(str, needReplace) {
			let repStr = str.replace(/\{\{.*?\}\}/g, "___");
			if(needReplace) {
				return escape2Html(repStr);
			} else {
				return repStr;
				
			}
		},
		closeModal(){
			this.$emit('on-close');
		},
	}
}
</script>
<style scoped>
	h4{
		margin:10px 0;
	}
</style>
